import { lazy } from 'react';

import type { RouteObject } from 'react-router-dom';
import { Navigate } from 'react-router-dom';

import lazyLoadComp from '@/router/lazyComp';

// 懒加载布局组件
const BasicLayout = lazy(() => import('@/layout/BasicLayout'));

// 设备接入-设备位置
const DeviceLocation = lazy(() => import('@/pages/Device/Location'));
// 设备接入-产品列表
const EquipmentProduct = lazy(() => import('@/pages/Equipment/Product'));
// 设备接入-产品详情
const EquipmentProductDetail = lazy(() => import('@/pages/Equipment/Product/modules/detail'));
// 设备接入-接入协议
const EquipmentAccessProtocol = lazy(() => import('@/pages/Equipment/AccessProtocol'));
// 设备接入-设备列表
const DeviceManager = lazy(() => import('@/pages/Device/Manager'));
// 设备接入-设备详情
const DeviceDetail = lazy(() => import('@/pages/Device/Manager/modules/detail'));
// 设备接入-设备分组
const DeviceGroups = lazy(() => import('@/pages/Device/Group'));
// 设备接入-设备分组详情
const DeviceGroupsDetail = lazy(() => import('@/pages/Device/Group/modules/detail'));
// 设备管理-组态图管理
const DeviceGraph = lazy(() => import('@/pages/Device/Graph'));
// 设备管理-组态图编辑
const DeviceGraphEdit = lazy(() => import('@/pages/Device/Graph/edit'));
// 设备管理-组态图查看
const DeviceGraphView = lazy(() => import('@/pages/Device/Graph/view'));
// 系统管理-角色管理
const SystemRole = lazy(() => import('@/pages/System/Role'));
// 系统管理-用户管理
const SystemUser = lazy(() => import('@/pages/System/User'));

// 规则引擎
const RulesConfig = lazy(() => import('@/pages/Rules/Config'));
// 规则引擎-告警规则详情
const WarningDetail = lazy(() => import('@/pages/Rules/Config/Warning/Detail'));
// 场景联动
const SceneLinkage = lazy(() => import('@/pages/Rules/Scene'));
const SceneDetail = lazy(() => import('@/pages/Rules/Scene/Detail'));
// 项目管理
const ProjectManger = lazy(() => import('@/pages/Project/Manager'));
const ProjectDetail = lazy(() => import('@/pages/Project/Manager/modules/detail'));
// 运维监控-告警中心
const OperationAlarm = lazy(() => import('@/pages/Operation/Alarm'));
// 运维监控-设备日志管理
const OperationLogs = lazy(() => import('@/pages/Operation/Logs'));
// 视频监控
const VideoMonitor = lazy(() => import('@/pages/Video/Monitor'));
// 视频监控详情
const VideoMonitorDetail = lazy(() => import('@/pages/Video/Monitor/detail'));

// 导入其他模块路由
const Dashboard = lazy(() => import('@/pages/Dashboard'));

const baseRouter: RouteObject[] = [
  {
    path: '/',
    id: 'root',
    element: lazyLoadComp(BasicLayout),
    children: [
      {
        index: true,
        element: <Navigate to="/dashboard" replace />,
      },
      {
        path: 'dashboard',
        id: 'dashboard',
        handle: {
          constant: true,
          title: '首页',
          icon: 'icon-menu-home',
          iconClass: '!text-5.5',
        },
        element: <Dashboard />,
      },
      {
        path: 'device',
        id: 'device',
        handle: {
          constant: true,
          title: '设备管理',
          icon: 'icon-menu-device',
          iconClass: 'text-blue-500',
        },
        children: [
          {
            index: true,
            element: <Navigate to="/device/list" replace />,
          },
          {
            path: 'list',
            id: 'device-list',
            handle: {
              constant: true,
              title: '设备列表',
              icon: 'icon-menu-manger',
            },
            element: <DeviceManager />,
          },
          {
            path: 'list/detail/:id',
            handle: {
              constant: true,
              hideMenu: true, // 隐藏在菜单中，因为这是详情页面
              title: '设备详情',
              icon: 'icon-all',
            },
            element: <DeviceDetail />,
          },
          {
            path: 'group',
            id: 'device-group',
            handle: {
              constant: true,
              title: '设备分组',
              icon: 'icon-menu-group',
            },
            element: <DeviceGroups />,
          },
          {
            path: 'group/detail/:id',
            handle: {
              constant: true,
              hideMenu: true, // 隐藏在菜单中，因为这是详情页面
              title: '分组详情',
              icon: 'icon-all',
            },
            element: <DeviceGroupsDetail />,
          },
          {
            path: 'location',
            id: 'device-location',
            handle: {
              constant: true,
              title: '设备位置',
              icon: 'icon-location',
            },
            element: <DeviceLocation></DeviceLocation>,
          },
          {
            path: 'graph',
            id: 'device-graph',
            handle: {
              constant: true,
              title: '组态图管理',
              icon: 'icon-menu-zt',
            },
            element: <DeviceGraph />,
          },
          {
            path: 'graph/edit/:id',
            handle: {
              constant: true,
              hideMenu: true,
              title: '编辑组态图',
              icon: 'icon-menu-zt',
            },
            element: <DeviceGraphEdit />,
          },
        ],
      },
      {
        path: 'equipment',
        id: 'equipment',
        handle: {
          constant: true,
          title: '设备接入',
          icon: 'icon-menu-device-entry',
          iconClass: 'text-green-500',
        },
        children: [
          {
            index: true,
            element: <Navigate to="/equipment/product" replace />,
          },
          {
            path: 'product',
            id: 'equipment-product',
            handle: {
              constant: true,
              title: '产品列表',
              icon: 'icon-menu-product',
            },
            element: <EquipmentProduct />,
          },
          {
            path: 'product/detail/:id',
            handle: {
              constant: true,
              hideMenu: true, // 隐藏在菜单中，因为这是详情页面
              title: '产品详情',
              icon: 'icon-all',
            },
            element: <EquipmentProductDetail />,
          },
          {
            path: 'access-protocol',
            handle: {
              constant: true,
              title: '泛协议接入',
              icon: 'icon-menu-access',
            },
            element: <EquipmentAccessProtocol />,
          },
        ],
      },
      {
        path: 'rules',
        id: 'rules',
        handle: {
          constant: true,
          title: '规则引擎',
          icon: 'icon-menu-gz',
        },
        children: [
          {
            index: true,
            element: <Navigate to="/config/warning" replace />,
          },
          {
            path: 'config/warning',
            handle: {
              constant: true,
              title: '规则配置',
              icon: 'icon-menu-rule-engine',
            },
            element: <RulesConfig />,
          },
          {
            path: 'config/warning/detail',
            handle: {
              constant: true,
              hideMenu: true, // 隐藏在菜单中，因为这是详情页面
              title: '告警规则配置',
              icon: 'icon-menu-rule-engine',
            },
            element: <WarningDetail />,
          },
          {
            path: 'config/scene',
            handle: {
              constant: true,
              title: '场景联动',
              icon: 'icon-menu-scene',
            },
            element: <SceneLinkage />,
          },
          {
            path: 'config/scene/detail',
            handle: {
              constant: true,
              hideMenu: true, // 隐藏在菜单中，因为这是详情页面
              title: '场景联动配置',
              icon: 'icon-menu-rule-engine',
            },
            element: <SceneDetail />,
          },
        ],
      },
      {
        path: 'operation',
        id: 'operation',
        handle: {
          constant: true,
          title: '运维监控',
          icon: 'icon-menu-operation',
        },
        children: [
          {
            index: true,
            element: <Navigate to="/operation/alarm" replace />,
          },
          {
            path: 'alarm',
            id: 'operation-alarm',
            handle: {
              constant: true,
              title: '告警中心',
              icon: 'icon-menu-alarm',
            },
            element: <OperationAlarm />,
          },
          {
            path: 'logs',
            id: 'operation-logs',
            handle: {
              constant: true,
              title: '设备日志',
              icon: 'icon-menu-device-logs',
            },
            element: <OperationLogs />,
          },
        ],
      },
      {
        path: 'project',
        id: 'project',
        handle: {
          constant: true,
          title: '项目管理',
          icon: 'icon-menu-manager',
        },
        children: [
          {
            index: true,
            element: <Navigate to="/project/manager" replace />,
          },
          {
            path: 'manager',
            handle: {
              constant: true,
              title: '项目列表',
              icon: 'icon-menu-project-list',
            },
            element: <ProjectManger />,
          },
        ],
      },
      {
        path: 'video',
        id: 'video',
        handle: {
          constant: true,
          title: '视频接入',
          icon: 'icon-menu-jr',
        },
        children: [
          {
            index: true,
            element: <Navigate to="/video/monitor" replace />,
          },
          {
            path: 'monitor',
            handle: {
              constant: true,
              title: '视频监控',
              icon: 'icon-menu-jk',
            },
            element: <VideoMonitor />,
          },
          {
            path: 'monitor/detail',
            handle: {
              constant: true,
              hideMenu: true, // 隐藏在菜单中，因为这是详情页面
              title: '视频监控详情',
              icon: 'icon-menu-jk',
            },
            element: <VideoMonitorDetail />,
          },
        ],
      },
      {
        path: 'system',
        id: 'system',
        handle: {
          constant: true,
          title: '系统管理',
          icon: 'icon-menu-sys',
        },
        children: [
          {
            index: true,
            element: <Navigate to="/system/role" replace />,
          },
          {
            path: 'role',
            id: 'system-role',
            handle: {
              constant: true,
              title: '角色管理',
              icon: 'icon-menu-role',
            },
            element: <SystemRole />,
          },
          {
            path: 'user',
            id: 'system-user',
            handle: {
              constant: true,
              title: '用户管理',
              icon: 'icon-menu-user',
            },
            element: <SystemUser />,
          },
        ],
      },
    ],
  },
  {
    path: '/device/graph/view/:id',
    id: 'device-graph-view-standalone',
    handle: {
      constant: true,
      hideMenu: true,
      title: '查看组态图',
      icon: 'icon-menu-zt',
    },
    element: <DeviceGraphView />,
  },
  {
    path: '*',
    id: '404-all',
    element: <div>404 页面未找到</div>,
  },
];

export default baseRouter;